﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MINERP.MODEL.FoundationModel;

namespace MINERP.MODEL.PaperManager
{
    public class PaperInfo_Info
    {
        #region 私有字段
        private int _paperTypeID;
        private int _paperFaceID;
        private int _printPaperId;
        private double _length;
        private double _endPaperLength;
        private DateTime _addTime;
        private double _lastLength;
        private DateTime _lastPrintTime;
        private string _remark;
        private int _status;
        private double _width;
        private int _printerID;
        private int _lastBordId;
        private double _paperConsumptionLength;
        private double _paperTitleArea;
        private double _paperEndArea;
        private double _invalidationArea;
        private double _validationArea;
        #endregion

        #region 公开属性
        public int PaperTypeID
        {
            get { return _paperTypeID; }
            set { _paperTypeID = value; }
        }
        public int PaperFaceID
        {
            get { return _paperFaceID; }
            set { _paperFaceID = value; }
        }
        public int PrintPaperId
        {
            get { return _printPaperId; }
            set { _printPaperId = value; }
        }
        public double Length
        {
            get { return _length; }
            set { _length = value; }
        }
        public double EndPaperLength
        {
            get { return _endPaperLength; }
            set { _endPaperLength = value; }
        }
        public DateTime AddTime
        {
            get { return _addTime; }
            set { _addTime = value; }
        }
        public double LastLength
        {
            get { return _lastLength; }
            set { _lastLength = value; }
        }
        public DateTime LastPrintTime
        {
            get { return _lastPrintTime; }
            set { _lastPrintTime = value; }
        }
        public string Remark
        {
            get { return _remark; }
            set { _remark = value; }
        }
        public int Status
        {
            get { return _status; }
            set { _status = value; }
        }
        public double Width
        {
            get { return _width; }
            set { _width = value; }
        }
        public int PrinterID
        {
            get { return _printerID; }
            set { _printerID = value; }
        }
        public int LastBordId
        {
            get { return _lastBordId; }
            set { _lastBordId = value; }
        }
        public double PaperConsumptionLength
        {
            get { return _paperConsumptionLength; }
            set { _paperConsumptionLength = value; }
        }
        public double PaperTitleArea
        {
            get { return _paperTitleArea; }
            set { _paperTitleArea = value; }
        }
        public double PaperEndArea
        {
            get { return _paperEndArea; }
            set { _paperEndArea = value; }
        }
        public double InvalidationArea
        {
            get { return _invalidationArea; }
            set { _invalidationArea = value; }
        }
        public double ValidationArea
        {
            get { return _validationArea; }
            set { _validationArea = value; }
        }
        public string PaperFaceName { get; set; }
        public string PaperTypeName { get; set; }
        public string StatusName
        {
            get
            {
                string strStatusName = string.Empty;
                switch (Status)
                {
                    case (int)MINERP.COM.PaperInfoStatus.Complete:
                        strStatusName = "完成";
                        break;
                    case (int)MINERP.COM.PaperInfoStatus.Using:
                        strStatusName = "正在打印";
                        break;
                    case (int)MINERP.COM.PaperInfoStatus.Used:
                        strStatusName = "使用一部份";
                        break;
                    case (int)MINERP.COM.PaperInfoStatus.New:
                        strStatusName = "还未使用";
                        break;
                    default:
                        break;
                }

                return strStatusName;
            }
        }

        private double _totalArea;
        /// <summary>
        /// 整轴纸面积
        /// </summary>
        public double TotalArea
        {
            get
            {
                if (_totalArea <= 0)
                {
                    _totalArea = Math.Round(Length * Width, 4);
                }
                return _totalArea;
            }
        }
        /// <summary>
        /// 浪费总面积
        /// </summary>
        public double WrasteArea { get; set; }
        /// <summary>
        /// 出片面积
        /// </summary>
        public double AvailabilityAread { get { return TotalArea - WrasteArea; } }
        /// <summary>
        /// 有效百分比        1- 浪费比+拼板浪费的比之后
        /// </summary>
        public double AvailabilityPer { get { return Math.Round(100.00d - TotalWrasterPer,2); } }

        private double _wrastePer = -1;
        /// <summary>
        /// 废纸的浪费百分比(指内部返单和添加废纸记录)
        /// </summary>
        public double WrastePer
        {
            get
            {
                if (_wrastePer < 0)
                {
                    _wrastePer = Math.Round((WrasteArea / TotalArea) * 100, 2);
                }
                return _wrastePer;
            }
        }

        public double TotalWrasterPer { get { return WrastePer + BarCodeAndBBAreaPer; } }
        /// <summary>
        /// 浪费的长度（主要指纸头、纸尾、卡纸、返单等）
        /// </summary>
        public double WateLength { get; set; }

        /// <summary>
        /// 打印了板的面积
        /// </summary>
        public double PrintBoardArea { get; set; }

        /// <summary>
        /// 条码和白边的浪费面积
        /// </summary>
        public double BarCodeAndBBArea { get; set; }

        private double _barCodeAndBBAreaPer = -1;

        /// <summary>
        /// 拼板浪费的比例
        /// </summary>
        public double BarCodeAndBBAreaPer
        {
            get
            {
                if (_barCodeAndBBAreaPer <= 0)
                {
                    _barCodeAndBBAreaPer = Math.Round((BarCodeAndBBArea / TotalArea) * 100, 2);
                }

                return _barCodeAndBBAreaPer;
            }
        }

        /// <summary>
        /// 当出片面积加上浪费面积小于总面积时就证明这轴纸有问题，反之变然
        /// </summary>
        public bool IsRight
        {
            get
            {
                if (PrintBoardArea + WrasteArea >= TotalArea)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }

        public List<PaperRecords_Info> UseRecords { get; set; }

        /// <summary>
        /// 是否所有的费纸都确认完成
        /// </summary>
        public string IsAllChecked
        {
            get
            {
                if (UseRecords.Count(p => p.Status != (int)MINERP.COM.WasterPaperStatus.Sure) > 0)
                {
                    return "未完成";
                }
                else
                {
                    return "完成";
                }
            }
        }
        #endregion
    }
}
